home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / nslookup / RCS / skip.c,v < prev    next >
Encoding:
Text File  |  1988-11-27  |  4.1 KB  |  193 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     88.11.23.13.39.26;  author douglis;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @original src from monet.
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/*
  27.  * Copyright (c) 1985 Regents of the University of California.
  28.  * All rights reserved.
  29.  *
  30.  * Redistribution and use in source and binary forms are permitted
  31.  * provided that the above copyright notice and this paragraph are
  32.  * duplicated in all such forms and that any documentation,
  33.  * advertising materials, and other materials related to such
  34.  * distribution and use acknowledge that the software was developed
  35.  * by the University of California, Berkeley.  The name of the
  36.  * University may not be used to endorse or promote products derived
  37.  * from this software without specific prior written permission.
  38.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  39.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  40.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  41.  */
  42.  
  43. #ifndef lint
  44. static char sccsid[] = "@@(#)skip.c    5.5 (Berkeley) 6/18/88";
  45. #endif /* not lint */
  46.  
  47. /*
  48.  *******************************************************************************
  49.  *
  50.  *  skip.c --
  51.  *
  52.  *    Routines to skip over portions of a query buffer.
  53.  *
  54.  *    Note: this file has been submitted for inclusion in
  55.  *    BIND resolver library. When this has been done, this file
  56.  *    is no longer necessary (assuming there haven't been any
  57.  *    changes).
  58.  *
  59.  *    Adapted from 4.3BSD BIND res_debug.c
  60.  *
  61.  *******************************************************************************
  62.  */
  63.  
  64. #include <sys/types.h>
  65. #include <netinet/in.h>
  66. #include <stdio.h>
  67. #include <arpa/nameser.h>
  68.  
  69. char *res_skip_rr();
  70.  
  71.  
  72. /*
  73.  *******************************************************************************
  74.  *
  75.  *  res_skip --
  76.  *
  77.  *     Skip the contents of a query.
  78.  *
  79.  *     Interpretation of numFieldsToSkip argument:
  80.  *            res_skip returns pointer to:
  81.  *        1 ->  start of question records.
  82.  *        2 ->  start of authoritative answer records.
  83.  *        3 ->  start of additional records.
  84.  *        4 ->  first byte after end of additional records.
  85.  *
  86.  *   Results:
  87.  *    (address)    - success operation.
  88.  *      NULL         - a resource record had an incorrect format.
  89.  *
  90.  *******************************************************************************
  91.  */
  92.  
  93. char *
  94. res_skip(msg, numFieldsToSkip, eom)
  95.     char *msg;
  96.     int numFieldsToSkip;
  97.     char *eom;
  98. {
  99.     register char *cp;
  100.     register HEADER *hp;
  101.     register int tmp;
  102.     register int n;
  103.  
  104.     /*
  105.      * Skip the header fields.
  106.      */
  107.     hp = (HEADER *)msg;
  108.     cp = msg + sizeof(HEADER);
  109.  
  110.     /*
  111.      * skip question records.
  112.      */
  113.     if (n = ntohs(hp->qdcount) ) {
  114.         while (--n >= 0) {
  115.             tmp = dn_skipname(cp, eom);
  116.             if (tmp == -1) return(NULL);
  117.             cp += tmp;
  118.             cp += sizeof(u_short);    /* type     */
  119.             cp += sizeof(u_short);    /* class     */
  120.         }
  121.     }
  122.     if (--numFieldsToSkip <= 0) return(cp);
  123.  
  124.     /*
  125.      * skip authoritative answer records
  126.      */
  127.     if (n = ntohs(hp->ancount)) {
  128.         while (--n >= 0) {
  129.             cp = res_skip_rr(cp, eom);
  130.             if (cp == NULL) return(NULL);
  131.         }
  132.     }
  133.     if (--numFieldsToSkip == 0) return(cp);
  134.  
  135.     /*
  136.      * skip name server records
  137.      */
  138.     if (n = ntohs(hp->nscount)) {
  139.         while (--n >= 0) {
  140.             cp = res_skip_rr(cp, eom);
  141.             if (cp == NULL) return(NULL);
  142.         }
  143.     }
  144.     if (--numFieldsToSkip == 0) return(cp);
  145.  
  146.     /*
  147.      * skip additional records
  148.      */
  149.     if (n = ntohs(hp->arcount)) {
  150.         while (--n >= 0) {
  151.             cp = res_skip_rr(cp, eom);
  152.             if (cp == NULL) return(NULL);
  153.         }
  154.     }
  155.  
  156.     return(cp);
  157. }
  158.  
  159.  
  160. /*
  161.  *******************************************************************************
  162.  *
  163.  *  res_skip_rr --
  164.  *
  165.  *     Skip over resource record fields.
  166.  *
  167.  *   Results:
  168.  *    (address)    - success operation.
  169.  *      NULL         - a resource record had an incorrect format.
  170.  *******************************************************************************
  171.  */
  172.  
  173. char *
  174. res_skip_rr(cp, eom)
  175.     char *cp;
  176.     char *eom;
  177. {
  178.     int tmp;
  179.     int dlen;
  180.  
  181.     if ((tmp = dn_skipname(cp, eom)) == -1)
  182.         return (NULL);            /* compression error */
  183.     cp += tmp;
  184.     cp += sizeof(u_short);    /*     type     */
  185.     cp += sizeof(u_short);    /*     class     */
  186.     cp += sizeof(u_long);    /*     ttl     */
  187.     dlen = _getshort(cp);
  188.     cp += sizeof(u_short);    /*     dlen     */
  189.     cp += dlen;
  190.     return (cp);
  191. }
  192. @
  193.